﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;

namespace TheOutfield.UmbExt.PrivateMessaging.Util
{
    public static class GenericExt
    {
        public static XPathNavigator ToXml<T>(this T obj)
        {
            DataContractSerializer dcs = new DataContractSerializer(typeof(T));
            StringBuilder sb = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(sb);
            dcs.WriteObject(writer, obj);
            writer.Close();

            var xml = XElement.Parse(sb.ToString());
            xml = xml.RemoveAllNamespaces();

            return xml.CreateNavigator();
        }
    }
}